package com.yy.adapter;

import java.util.HashMap;
import java.util.List;

import com.yy.bean.Hero;
import com.yy.mydota.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyGridViewAdapter extends BaseAdapter {
	private static String TAG = "MyGridViewAdapter";
	
	private Context mContext;
	private List<Hero> mlist;
	
	class ListItemView {
		public ImageView iv_hero_ico;
		public TextView texv_hero_name;
	}
	
	public MyGridViewAdapter(Context context, List<Hero> list){
		this.mContext = context;
		this.mlist = list;
		
	}
	
	@Override
	public int getCount() {
		return mlist==null?0:mlist.size();
	}

	@Override
	public Object getItem(int position) {
		return mlist==null?null:mlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView listItem = null;
		if (convertView == null) {
			listItem = new ListItemView();
			convertView = View.inflate(mContext, R.layout.item_hero_list,
					null);
			listItem.iv_hero_ico = (ImageView) convertView
					.findViewById(R.id.iv_hero_ico);
			listItem.texv_hero_name = (TextView) convertView
					.findViewById(R.id.texv_hero_name);
			
			convertView.setTag(listItem);
		} else {
			listItem = (ListItemView) convertView.getTag();
		}

		listItem.iv_hero_ico.setImageResource(mlist.get(position).getImageID());
		listItem.texv_hero_name.setText(mlist.get(position).getName());
		return convertView;
	}

}
